<?php
    session_start();
    include_once '../../../../controlador/php/conexion/Conexion.php';
    $con = new Conexion();
    
    $oid = $_REQUEST['oid'];
    $n = $_REQUEST['n'];
    $usuario = $_SESSION['usuario'];
    
     $count="select COUNT(*)as num from segtomado where hcnsolexa = '".$oid."'";
     $res = $con->query($count);
     
     while($res2 = mssql_fetch_array($res)){
        $num = $res2['num'];
     } 
     if ($num == 0){
         if($usuario == ""){
             print_r(json_encode(array('n'=>1)));
         }
         else{
            $inser= "insert into segtomado(hcnsolexa,tmfecha,tmestado,usu_oid,tmpnt,tmcual,tmestadon,usu_oidn,tmfechan)values('".$oid."','','','','".$n."','','1','".$_SESSION['usuario']."',GETDATE())";
            $con->query($inser);
            print_r(json_encode(array('n'=>2)));
         }
     }else{
         if($usuario == ""){
             print_r(json_encode(array('n'=>1)));
         }
         else{
           $update = "update segtomado
                       set tmpnt = '".$n."',
                       tmestadon = '1',
                       usu_oidn = '".$_SESSION['usuario']."',
                       tmfechan = GETDATE()
                       where hcnsolexa = '".$oid."'";
            $con->query($update);
            print_r(json_encode(array('n'=>2)));
         }
     }
    $con->cerrarConexion();
    
 
?>